<jsp:useBean id="utilisateur" class="fr.p10.miage.gestionabsence.model.Utilisateur" scope="session"/>
<%@page import="fr.p10.miage.gestionnote.model.Note"%>
<%@page import="fr.p10.miage.gestionnote.model.EcsIntervenant"%>
<%@page import="fr.p10.miage.gestionnote.model.Controle"%>
<%@page import="java.util.List"%>
<%@page import="fr.p10.miage.gestionnote.model.EcIntervenant"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!doctype html>
<html lang="fr" >
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="shortcut icon" href="">
        <title>Ajout d'un contrôle</title>
        <link href="css/bootstrap.css" rel="stylesheet">
        <link href="css/font-awesome.css" rel="stylesheet">
        <link href="css/index-bo.css" rel="stylesheet">
    </head>

    <body class="skin-black fixed">
        <%@include file="../../../header.jsp" %>
        <div class="wrapper row-offcanvas row-offcanvas-left">
            <%@include file="../../../asideLeft.jsp" %>
            <aside class="right-side">
                <%
                    EcsIntervenant listeEcsIntervenant = (EcsIntervenant) request.getSession().getAttribute("listeEcsIntervenant");
                    int idec =Integer.parseInt(request.getParameter("idec"));
                    int idp =Integer.parseInt(request.getParameter("idp"));
                    
                    EcIntervenant ecIntervenant = listeEcsIntervenant.getEcIntervenantById(idec,idp);
                    Controle controle = (Controle) request.getAttribute("controle");
                %>
                <section class="content-header">
                    <h1>Consulter et modifier le contrôle : <% out.print(controle.getLabel());%> de l'EC <% out.print(ecIntervenant.getNom());%></h1>
                    <html:link action="/ec-detail" linkName="Liste ec">
                        <button type="button" class="btn btn-default pull-right" style="background-color: #eee; margin-bottom: 15px;" ><span class="glyphicon glyphicon-chevron-left" ></span> Retour</button>
                        <html:param name="idec">
                            <% out.print(ecIntervenant.getIdec());%>
                        </html:param>
                        <html:param name="idp">
                                <% out.print(ecIntervenant.getIdP()); %>
                        </html:param>
                    </html:link>
                </section>
                <section class="content">
                    <div class="container-fluid">
                    <form class="form-horizontal" action="ec-modifier-controle.do">    
                    <h2>Informations</h2>

                    <div class="form-group">
                        <label for="label" class="col-sm-2 control-label">Label</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control input-required" name="label" placeholder="Label" value="<%= String.valueOf(controle.getLabel()) %>">
                            <span class="glyphicon glyphicon-warning-sign form-control-feedback hidden" style="display:none"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="coefficient" class="col-sm-2 control-label">Coefficient</label>
                        <div class="col-sm-5">
                            <input type="text" data-mask="999.99" class="form-control input-required" name="coefficient" placeholder="Coefficient" value="<%= String.valueOf(controle.getCoefficient()) %>">
                            <span class="glyphicon glyphicon-warning-sign form-control-feedback" style="display:none"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="echelle" class="col-sm-2 control-label">Echelle de notation</label>
                        <div class="col-sm-5">
                            <input type="text" data-mask="999" class="form-control echelle input-required" name="echelle" placeholder="Echelle de notation" value="<%= String.valueOf(controle.getEchelle()) %>">
                            <span class="glyphicon glyphicon-warning-sign form-control-feedback" style="display:none"></span>
                        </div>
                    </div>
                    <div class="form-group">
                      <label for="type" class="col-sm-2 control-label">Type</label>
                      <div class="col-sm-5">
                        <select name="type" class="form-control">
                          <option value="<%=String.valueOf(Controle.DST)%>" <%if(controle.getType()==Controle.DST){ out.println("selected"); }%>>Contôle</option> 
                          <option value="<%=String.valueOf(Controle.PARTIEL)%>" <%if(controle.getType()==Controle.PARTIEL){ out.println("selected"); }%>>Partiel</option>
                        </select>
                      </div>
                    </div>
                    <input type="hidden" name='idp' 
                                   value="<%=String.valueOf(ecIntervenant.getIdP())%>">
                    <input type="hidden" name='idec'
                                   value="<%=String.valueOf(ecIntervenant.getIdec())%>">
                    <input type="hidden" name='sizeListeNote'
                                   value="<%=String.valueOf(ecIntervenant.getEtudiants().size())%>">
                     <input type="hidden" name='idcontrole'
                                   value="<%=String.valueOf(controle.getIdcontrole())%>">
                    <html:errors/>
                    <h2>Liste des élèves</h2>
                    <div class="row">
                        
                            <%
                                Note note = null;
                                if (ecIntervenant != null) {
                                    for (int i = 0; i < ecIntervenant.getEtudiants().size(); i++) {
                                    note = controle.getNoteByEtudiantId(ecIntervenant.getEtudiants().get(i).getId());
                            %>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">
                                    <%out.println(ecIntervenant.getEtudiants().get(i).getNom());%>
                                    <%out.println(ecIntervenant.getEtudiants().get(i).getPrenom());%>
                                </label>
                                <input type="hidden" name='<%= "idEtudiant" + i%>' class="form-control"
                                       value="<%=String.valueOf(ecIntervenant.getEtudiants().get(i).getId())%>">
                                <div class="col-sm-2">
                                <input type="text" 
                                       class="form-control" 
                                       data-mask="999.99"
                                       name="<%= "note" + i%>" 
                                       value="<%if(note!=null){ out.println(note.getNote()); }%>">    
                                </div>
                                <div class="col-sm-1">
                                    <p>/<span class="echelle-choisie">?<span></p>
                                </div>
                                <div class="col-sm-2">
                                <input class="dispense-checkbox" 
                                       type="checkbox" 
                                       name='<%= "dispense" + i%>'
                                       <%if(note!=null && note.getDispense()){ out.println("checked"); }%>> Dispenser
                                </div>
                            </div>
                            <%
                                    }
                                }
                            %>
                            <div class="form-group">
                                <div class="col-sm-5">
                                </div>
                                <div class="col-sm-2">
                                    <input class="dispense-all-checkbox" type="checkbox"><span class="label-dispense-all-checkbox"> Sélectionner tout</span>
                                </div>
                            </div>    
                    </div>
                    <div class="row">        
                            <div class="col-sm-5 action">        
                                <div class="alert alert-warning controle-checkbox-notification" style="display:none">
                                        <span class="glyphicon glyphicon-info-sign"></span>
                                        Si vous dispensez un éleve sa note sera automatiquement mise à zero !<br />
                                        Assurément cette note ne sera pas prise en compte dans le calcul de sa moyenne.
                                </div>
                            </div>
                    </div>    
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                             <html:submit styleClass="btn btn-default">
                                 <bean:message key="button.modifier" />
                             </html:submit>
                        </div>
                    </div>
                </form>
                </div>  
                </section>
            </aside>
        </div>
        <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
        <script src="js/bootstrap.js"></script>
        <script src="js/jquery.decimalMask.js"></script>
        <script src="js/treeview.js"></script>
        <script>
            $(document).ready(function(){
                $('[data-mask]').each(function (){
                    $(this).decimalMask($(this).attr('data-mask'));
                });
                
                /*$('.input-required').blur(function(){
                    if($('.input-required').val() == ''){
                       $('.input-required').parents(".form-group").addClass("has-warning has-feedback")
                       $('.input-required').parents(".form-group").find('span').show();
                    }
                 });*/

                $(".controle-checkbox-notification").hide();
                
                if ($('.dispense-checkbox').prop('checked')) 
                {
                    $(".controle-checkbox-notification").slideDown();
                }

                
                $('.dispense-checkbox').click(function(){
                    if (this.checked) {
                        $(".controle-checkbox-notification").slideDown();
                    }
                });
                
                
                $('.dispense-all-checkbox').click(function()
                {
                    if (this.checked) 
                    {
                        $(".dispense-checkbox").prop('checked', true);
                        $(".label-dispense-all-checkbox").text(' Déselectionner tout');
                    }
                    else
                    {
                        $(".dispense-checkbox").prop('checked', false);
                        $(".label-dispense-all-checkbox").text(' Sélectionner tout');
                    }
                });
                 $(".echelle-choisie").text($('.echelle').val());
                 $('.echelle').change(function()
                 {
                     $(".echelle-choisie").text($( this ).val());
                });
            });
        </script>    
</body>
</html>
